<template>
	<view>
		<view class="head">
			<uni-icons type="back" size="22px" color="#1F8AF3" style="margin-top: 14px; margin-left: 5px; font-weight: 700;" @click="toHome()"></uni-icons>
			<view class="search-bar-box">
			<uni-icons type="search" size="13px" color="#C7C7C9" style="margin-top: 10px;margin-left: 9px;"></uni-icons>
			<input type="text" value="" v-model="keyword" placeholder="请输入专业课名称" class="search-text" maxlength="10" focus/>

			</view>
			<button type="primary" class="button-btn">搜索</button>
		</view>
		<view class="body">
			<view class="goods"
				v-for="(item,index) in dataList"
				:key="index"
			>
				<image :src="item.imgUrl" mode="aspectFit"></image>
				<view class="content" @click="information(item.id)">
					<text>{{item.name}}</text>
					<view class="content1">
						<text class="price">￥{{item.price}}</text>
						<text class="time">{{item.uploadTime}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import axios from 'axios'
	export default{
		data(){
			return{
				keyword:"",
				dataList:[],
			}
		},
		created() {
			// this.getListData()
      //mgl修改
      let that = this
			this.$axios.get("/goods/search",{
				params:{
					key:that.keyword,
				},
				headers:{
					'token': localStorage.getItem('token')
        }
			}).then(res=>{
					// this.dataList=res.data.data;
					res.data.data.map(item => {
					  if (item.fileType === 0) 
									item.imgUrl = '../../static/pdficon.jpeg'
					  else if (item.fileType === 1 || item.fileType ===2) 
									item.imgUrl = '../../static/docIcon.jpg'
					  else 
									item.imgUrl = '../../static/pdficon.jpeg' //默认为pdf 
					
					  item.uploadTime = new Date()
					})
					for (var i = 0;i<res.data.data.length;i++) {

						if(res.data.data[i].name.indexOf(this.keyword)>=0){
							this.dataList.push(res.data.data[i]);
						}
					}
					// console.log(this.dataList);
					if(this.dataList.length == 0){
						uni.showToast({
							title:"暂无此专业课",
							icon:"none"
						})
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/index/search',
							})
						},1000)
					}
					// console.log(this.dataList)
					// console.log("keyword:"+this.keyword)
				}).catch(()=>{
						uni.showToast({
							title:"请求失败",
							icon:"none"
						})
					})
		},
		onLoad(e) {
		    this.keyword=e.keyword;
		    // console.log("e.keyword:"+e.keyword)
		},
		methods:{
			toHome(){
				// console.log(111)
				uni.navigateTo ({
					url:'/pages/index/search',
					success() {
						console.log("跳转成功")
					},
					fail() {
						console.log("跳转失败")
					}

				})
			},
			information(id){
				uni.navigateTo({
					url:'/pages/index/details?id='+id+'',
					// url:"/pages/profession/productDetails?keyword="+item+""
				})
			}
		}
	}
</script>

<style>
	/*head部分*/
	.search-bar{
		width: 100%;
		height: 100rpx;
		margin-top: 2%;
	}
	.search-bar-box{
		display: flex;
		margin: 0 auto;
		width: 75%;
		height: 37px;
		background-color: #FFFFFF;
		border:5rpx solid #EEEEEF;
		border-radius: 12px;
		/* background-color: rgba(255, 255, 255, 1); */
		margin-top: 6px;
	}
	.search-span{
		width: 100rpx;
		height: 56rpx;
		margin-top: 6rpx;
		margin-left: 30rpx;
	}
	.search-text{
		width: 100%;
		margin-top: 6px;
		margin-left: 20rpx;
		font-size: 30rpx;
		color: #7f7f81;
	}
	.search-btn{
		background-color: #00a8cc; /* Green */
		color: white;
		text-align: center;
		display: inline-block;
		font-size: 35rpx;
		width: 240rpx;
		height: 70rpx;
		line-height: 65rpx;
		border-radius: 30rpx;
		letter-spacing: 3rpx;
	}

	.head{
		display: flex;
		justify-content: flex-start;
		background-color: #EEEEEF;
	}
	/deep/.uni-searchbar__box[data-v-180dbe05]{
		height: 34px;
		justify-content: flex-start;
	}
	.uni-searchbar[data-v-180dbe05]{
		width: 85%;
	}
	.button-btn{
		margin-top: 9px;
		width: 60px;
		height: 34px;
		font-size: 14px;
		border-radius: 12px;
		margin-right: 2px;
	}
	/*body部分*/
	.body{
		background: #EEEEEF;
		overflow: hidden;

	}
	.goods{
		display: flex;
		width: 100%;
		height: 120px;
		background: #fff;
		margin: 7px 0;
	}
	uni-image{
		width: 130px;
		height: 85px;
		margin-top: 17px;
	}
	text{
		font-size: 14px;
		color: #101010;

	}
	.content{
		margin-top: 10px;
		margin-right: 46px;

	}
	.content1{
		margin-top: 43px;
	}
	.price{
		color: #ff0000;
		font-size: 16px;
		margin-right: 65px;
		font-weight: 700;
	}
	.time{
		color: #9FA1A3;
		font-size: 12px;
	}
	.search[data-v-1ec26858]{
		padding-top: 3px;
	}
	/deep/.uni-searchbar__box{
		justify-content: flex-start;
		height: 28px;
	}
	.uni-searchbar{
		width: 90%;
		margin-left: 18px;
	}
</style>
